﻿using System;
using Machine.Entity;
using System.Linq.Expressions;
using Machine.Model.ReturnModel;
using Machine.IRepository;
using Machine.Repository;
using Machine.Helper;
namespace Machine.Bussiness
{
    public class MachineWXBLL : BaseBLL<MachineBX>
    {
        private IMachineWX DAL = new MachineWXDAL();

        public override void SetCurrentRepository()
        {
            CurrentRepository = DAL;//CurrentRepository属性在BaseBLL中定义
        }

        public string getNextSeq(string kind)
        {
            string startWith = kind;
            string ym = DateTime.Now.ToString("yyMM");
            startWith = startWith + ym;
            Expression<Func<MachineBX, bool>> where = (p => p.WXID.StartsWith(startWith));
            Expression<Func<MachineBX, object>> order = (p => p.WXID);
            MachineBX newT = CurrentRepository.GetMaxEntiy(where, order);
            string sNext;
            if (newT == null)
            {
                sNext = startWith + "001";
            }
            else
            {
                sNext = startWith + StringHelper.GetNext(newT.WXID, 3);
            }
            return sNext;
        }

        public object GetPageList(string role, string uid, string status, int pageIndex, int pageSize, string recid = "0")
        {
            return DAL.GetPageList(role, uid, status, pageIndex, pageSize, recid);
        }

        public object getMachineWX(string WXID)
        {
            return DAL.getMachineWX(WXID);
        }

        public object getListByKey(string key, string recid = "0", int pageIndex = 1, int pageSize = 10)
        {
            return DAL.getListByKey(key, recid, pageIndex, pageSize);
        }

        public object getDelList(int pageIndex = 1, int pageSize = 10)
        {
            return DAL.getDelList(pageIndex, pageSize);
        }

        public int updateEntity(MachineBX Entity)
        {
            return DAL.updateEntity(Entity);
        }

        public int updateStatus(string wxid, string uid, string wxstatus)
        {
            if (wxstatus == "WX")
            {
                return DAL.updateWX(wxid, uid);
            }
            else if (wxstatus == "FN")
            {
                return DAL.updateFN(wxid, uid);
            }
            else
            {
                return DAL.updateCN(wxid);
            }
        }
    }
}
